//
//  KZShadowButton.m
//  听说弱点强化训练
//
//  Created by 朱凯 on 2018/8/22.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "KZShadowButton.h"

@implementation KZShadowButton
{
    UIButton *_button;
}

- (instancetype)init:(void (^)(UIButton *))config {
    
    if (self = [super init]) {
        
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.backgroundColor = UIColor.blueColor;
        _button.layer.cornerRadius = 4;
        _button.layer.masksToBounds = true;
        _button.titleLabel.font = FONT(15);
        [_button setTitle:@"按钮" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self addSubview:_button];
        [_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        if (config) {
            config(_button);
        }
    }
    return self;
}
- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.layer.shadowColor = _button.backgroundColor.CGColor;
    self.layer.shadowRadius = 10;
    self.layer.shadowOpacity = 0.5;
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(10, 20)];
    [path addLineToPoint:CGPointMake(15, self.height + 5)];
    [path addLineToPoint:CGPointMake(self.width - 15, self.height + 5)];
    [path addLineToPoint:CGPointMake(self.width - 10, 20)];
    [path closePath];
    self.layer.shadowPath = path.CGPath;
}

@end
